package glz.hawk.bookstore.mapper;

import static glz.hawk.bookstore.mapper.AuthorDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

import glz.hawk.bookstore.model.Author;
import jakarta.annotation.Generated;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface AuthorMapper extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<Author>, CommonUpdateMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    BasicColumn[] selectList = BasicColumn.columnList(authorId, authorName);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.574585+08:00", comments="Source Table: author")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="AuthorResult", value = {
        @Result(column="AUTHOR_ID", property="authorId", jdbcType=JdbcType.DECIMAL, id=true),
        @Result(column="AUTHOR_NAME", property="authorName", jdbcType=JdbcType.VARCHAR)
    })
    List<Author> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("AuthorResult")
    Optional<Author> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, author, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, author, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default int deleteByPrimaryKey(BigDecimal authorId_) {
        return delete(c -> 
            c.where(authorId, isEqualTo(authorId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default int insert(Author row) {
        return MyBatis3Utils.insert(this::insert, row, author, c ->
            c.map(authorId).toProperty("authorId")
            .map(authorName).toProperty("authorName")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default int insertMultiple(Collection<Author> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, author, c ->
            c.map(authorId).toProperty("authorId")
            .map(authorName).toProperty("authorName")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default int insertSelective(Author row) {
        return MyBatis3Utils.insert(this::insert, row, author, c ->
            c.map(authorId).toPropertyWhenPresent("authorId", row::getAuthorId)
            .map(authorName).toPropertyWhenPresent("authorName", row::getAuthorName)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default Optional<Author> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, author, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default List<Author> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, author, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default List<Author> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, author, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default Optional<Author> selectByPrimaryKey(BigDecimal authorId_) {
        return selectOne(c ->
            c.where(authorId, isEqualTo(authorId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, author, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    static UpdateDSL<UpdateModel> updateAllColumns(Author row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(authorId).equalTo(row::getAuthorId)
                .set(authorName).equalTo(row::getAuthorName);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Author row, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(authorId).equalToWhenPresent(row::getAuthorId)
                .set(authorName).equalToWhenPresent(row::getAuthorName);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default int updateByPrimaryKey(Author row) {
        return update(c ->
            c.set(authorName).equalTo(row::getAuthorName)
            .where(authorId, isEqualTo(row::getAuthorId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2025-08-19T10:57:44.5757473+08:00", comments="Source Table: author")
    default int updateByPrimaryKeySelective(Author row) {
        return update(c ->
            c.set(authorName).equalToWhenPresent(row::getAuthorName)
            .where(authorId, isEqualTo(row::getAuthorId))
        );
    }
}